package org.sy.lab.多线程基础._2_同步._2_ReentrantLock._3_公平锁;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Tick {
	
	private Lock lock = new ReentrantLock(false);
	
	public void add() {
		lock.lock();
		System.out.println(Thread.currentThread().getName() + "进入锁");
		try {
			TimeUnit.SECONDS.sleep(1);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		//System.out.println(Thread.currentThread().getName() + "离开锁");
		lock.unlock();
		
		lock.lock();
		System.out.println(Thread.currentThread().getName() + "进入锁2");
		try {
			TimeUnit.SECONDS.sleep(1);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		//System.out.println(Thread.currentThread().getName() + "离开锁2");
		lock.unlock();
	}
}
